package com.itheima.controller;

import com.itheima.pojo.NursingProject;
import com.itheima.pojo.NursingProjectQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.NursingProjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/serve/project")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;
    //分页查询
    @GetMapping("/list")
    public Result page(NursingProjectQueryParam nursingProjectQueryParam){
        log.info("查询请求参数：{}",nursingProjectQueryParam);
        PageResult pageResult = nursingProjectService.page(nursingProjectQueryParam);
        return Result.success(pageResult);
    }



    @PostMapping
    //增加护理项目
    public Result save(@RequestBody NursingProject nursingProject){
        boolean save = nursingProjectService.save(nursingProject);
        return Result.success(save);
    }

    @DeleteMapping
    public Result remove(@RequestParam List<Integer> ids){
        log.info("批量删除员工，员工id：{}",ids);
        nursingProjectService.removeByIds(ids);
        return Result.success();
    }

    @GetMapping("/all")
    public Result findAll(){
        return Result.success(nursingProjectService.list());
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("根据id查询，员工ID",id);
        return Result.success(nursingProjectService.getById(id));
    }
    @PutMapping
    public Result update(@RequestBody NursingProject nursingProject){
        nursingProjectService.updateById(nursingProject);
        return Result.success();
    }


}
